﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.OracleClient;
using System.Configuration;
using System.Text;

/// <summary>
/// Customer 的摘要描述
/// </summary>
public class Customer
{

	public Customer()
	{
		//
		// TODO: 在此加入建構函式的程式碼
		//
	}
    private DateTime _dataData;
    public DateTime dataData
    {
        get
        {
            return _dataData;
        }
        set
        {
            _dataData = value;
        }
    }
    private string _customerID;
    public string customerID
    {
        get
        {
            return _customerID;
        }
        set
        {
            _customerID = value;
        }
    }
    private string _shortName;
    public string shorName
    {
        get
        {
            return _shortName;
        }
        set
        {
            _shortName = value;
        }
    }
    private string _legalName;
    public string legalName
    {
        get
        {
            return _legalName;
        }
        set
        {
            _legalName = value;
        }
    }
    private string _groupID;
    public string groupID
    {
        get
        {
            return _groupID;
        }
        set
        {
            _groupID = value;
        }
    }
    private string _fullName;
    public string fullName
    {
        get
        {
            return _fullName;
        }
        set
        {
            _fullName = value;
        }
    }
    private string _city;
    public string city
    {
        get
        {
            return _city;
        }
        set
        {
            _city = value;
        }
    }
    private string _country;
    public string country
    {
        get
        {
            return _country;
        }
        set
        {
            _country = value;
        }
    }
    private string _unino;
    public string unino
    {
        get
        {
            return _unino;
        }
        set
        {
            _unino = value;
        }
    }
    private string _logicalCountry;
    public string logicalCountry
    {
        get
        {
            return _logicalCountry;
        }
        set
        {
            _logicalCountry = value;
        }
    }
    private string _physicalCountry;
    public string physicalCountry
    {
        get
        {
            return _physicalCountry;
        }
        set
        {
            _physicalCountry = value;
        }
    }

    /// <summary>
    /// 從ODS資料庫取得Customer Definition
    /// Table Name:OD_OB_CUST
    /// </summary>
    public void getCustDataFromODS()
    {
        using (OracleConnection conn = new OracleConnection())
        {
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString_ODS"].ConnectionString;
            conn.Open();
            OracleCommand cmd = conn.CreateCommand();
            StringBuilder sb = new StringBuilder();
            sb.Append("SELECT DATADT,CUST,FULLNAME,GRP,SHORTNAME,LEGALNAME,COUNTRY,CITY,UNINO,LOGICALCOUNTRY,PHYSICALCOUNTRY FROM OD_OB_CUST WHERE CUST='" + _customerID + "'");
            string sqlStr = sb.ToString();
            cmd.CommandText = sqlStr;

            // Read oracle data
            OracleDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                _dataData = reader["DATADT"] != DBNull.Value ? (DateTime)reader["DATADT"] : DateTime.Now;
                _fullName = reader["FULLNAME"] != DBNull.Value ? ((string)reader["FULLNAME"]).TrimEnd().ToString() : "";
                _groupID = reader["GRP"] != DBNull.Value ? ((string)reader["GRP"]).TrimEnd().ToString() : "";
                _shortName = reader["SHORTNAME"] != DBNull.Value ? ((string)reader["SHORTNAME"]).TrimEnd().ToString() : "";
                _legalName = reader["LEGALNAME"] != DBNull.Value ? ((string)reader["LEGALNAME"]).TrimEnd().ToString() : "";
                _country = reader["COUNTRY"] != DBNull.Value ? ((string)reader["COUNTRY"]).TrimEnd().ToString() : "";
                _city = reader["CITY"] != DBNull.Value ? ((string)reader["CITY"]).TrimEnd().ToString() : "";
                _unino = reader["UNINO"] != DBNull.Value ? ((string)reader["UNINO"]).TrimEnd().ToString() : "";
                _logicalCountry = reader["LOGICALCOUNTRY"] != DBNull.Value ? ((string)reader["LOGICALCOUNTRY"]).TrimEnd().ToString() : "";
                _physicalCountry = reader["PHYSICALCOUNTRY"] != DBNull.Value ? ((string)reader["PHYSICALCOUNTRY"]).TrimEnd().ToString() : "";
            }
            conn.Close();
        }
    }
}
